<#import "/macro.ftl" as m>
<@m.page_header  />
<script type="text/javascript" src="/assets/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/assets/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="/assets/ueditor/lang/zh-cn/zh-cn.js"></script>
 
<div id="page-content-wrapper">
<div id="page-title">

    <h3>
        <#if page>修改页面<#else>添加页面</#if>
    </h3>
</div>
<#if error??>
	<div class="infobox error-bg mrg20B">
        <p>${error}</p>
    </div>
</#if>
<div class="pad10A">
<form id="demo-form1" action="/page/<#if addorexit>add<#else>update</#if>" class="col-md-12" method="POST">
	<#if page !=null>
	<input type="hidden" name="id" value="${page.id}"/>
	</#if>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                标题:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <input type="text" id="title" name="title"  data-trigger="change" data-required="true" class="parsley-validated" value="${((page.title)!'')?xhtml}">
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                URL:<span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <input type="text" id="title" name="name"  data-trigger="change" data-required="true" class="parsley-validated" value="${((page.name)!'')?xhtml}">
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                关键字:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <input type="text" id="metaKeywords" name="metaKeywords"  data-trigger="change" data-required="true" class="parsley-validated" value="${((page.metaKeywords)!'')?xhtml}">
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                H5重定向地址:
            </label>
        </div>
        <div class="form-input col-md-3">
            <input type="text" id="h5redirect" name="h5redirect"  data-trigger="change" class="parsley-validated" value="${page.h5redirect!}">
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                分类:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <span class="td_val">
				<select id="parent">
					 <option value="">请选择...</option>
					<#list parentPageCategories as pageCategory>
						<option value="${pageCategory.id}" <#if (pageCategory.id == page.pageCategory.id)!>selected = "selected"</#if>>${pageCategory.name}</option>
					</#list>
				</select>
			</span>
        </div>
        <div class="form-input col-md-3">
            <span class="td_val">
				<select class="ml13" id="child" name="pageCategory.id"><option value="">请选择...</option></select>
			</span>
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                模版:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <span class="td_val">
				 <select id="pageTemplateId"  name="pageTemplate.id">
				   <option value="">请选择模板</option>
				   <#list pageTemplate as template>
					<option value="${template.id}"<#if (template.id == page.pageTemplate.id)!>selected = "selected"</#if>>${template.title}</option>
				   </#list>
				</select>
			</span>
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                内容:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
		 	<textarea id="uecontent" name="content" placeholder="请输入页面模板" style="width:600px;height:400px;">${(page.content)!}</textarea>
        </div>
    </div>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                是否发布:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            <span class="td_val">
				 <select name="published" class="ip1">
					<option value="false" <#if (!page.published)!>selected = "selected"</#if>>未发布</option>
					<option value="true" <#if (page.published)!>selected = "selected"</#if>>发布</option>
				 </select>
			</span>
        </div>
    </div>
    <#if page>
    <div class="form-row">
        <div class="form-label col-md-2">
            <label for="">
                创建人:
                <span class="required">*</span>
            </label>
        </div>
        <div class="form-input col-md-3">
            ${((page.author)!'')?xhtml}
        </div>
    </div>
    </#if>
    <div class="divider"></div>
    <div class="form-row">
        <input type="hidden" name="superhidden" id="superhidden">
       <div class="form-input col-md-10 col-md-offset-2">
                    <a href="javascript:;" class="btn medium primary-bg radius-all-4 col-md-2" id="demo-form-2-valid">
                        
                                                                         提交
                        
                 </a>
        </div>
    </div>   
</form>
</div>
</div>

 
<!-- 实例化编辑器 -->
<script type="text/javascript">
<#if page!=null>
	var uySaveFloder ="page/${page.id}";
</#if>
<#if page==null>
	var uySaveFloder ="page/"+new Date().getFullYear()+""+new Date().getMonth()+""+new Date().getDate();
</#if>
	var editor = UE.getEditor('uecontent',{upYunSaveFolder:uySaveFloder});
	editor.options.allowDivTransToP=false;

	var pageCategory = {
		<#list parentPageCategories as parentPageCategory>
			"${parentPageCategory.id}":[
				<#list parentPageCategory.children as childrenPageCategory>
					{"id":${childrenPageCategory.id},"name":"${childrenPageCategory.name}"},
				</#list>
			],
		</#list>
	};
	function change(id){
		$('#child').html('');
		$.each(pageCategory[id], function(i,e){
			$('#child').append($('<option>', {
			    value: e.id,
			    text: e.name
			}));
		});
	};
	$(function(){
		pageCategory = eval(pageCategory);
		
		<#if (page.pageCategory.id)!>
			change("${(page.pageCategory.parent.id)!}");
			$('#parent').val("${(page.pageCategory.parent.id)!}");
			$("#child option[value='${(page.pageCategory.id)!}']").attr("selected",true);
		</#if>
		$('#parent').change(function(){
			change(this.value);
		});
		
		$("#demo-form-2-valid").click(function(){
			if($('#parent').val()==""||$('#pageTemplateId').val()==""){
				alert("分类或模板未填");
				return;
			}
			$('#demo-form1').parsley('validate');
	    	$('#demo-form1').trigger('submit');
		});
	});
	
	
</script>
<@m.page_footer />